<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*;" %>

<% 
		Thread.sleep(2000);
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		String url = "jdbc:sqlserver://192.168.38.73:1433;database=PJDB";

		String query = "select count(*) from member where mbaccount=?";
		String mbaccount = request.getParameter("mbaccount");

		try{

			DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());
			conn = DriverManager.getConnection(url, "sa", "sa123456");

			stmt = conn.prepareStatement(query);
			stmt.setString(1,mbaccount);
			
			
			rs = stmt.executeQuery();
			String strMsg = "帳號可以使用";
			
			 rs.next();
			 if(rs.getInt(1) >= 1){
				 strMsg =  "帳號已存在";
			 }
			 out.print(strMsg);
 
			 
		}
		catch(SQLException e){
			out.println("Error:" + e.getMessage());
		}
		finally{
			if(rs != null){
			   rs.close();
			}
			if(stmt != null){
			 stmt.close();
			}
			if(conn != null){
			}
		}

%>